﻿/**
 * 功能:砍箱子公告信息

*/
var setupTask;
//设置每次副本开启的分钟段(分钟:为单位)
var startminute = 8;

//设置每次活动结束的时间(分钟:为单位)
var overtime = 20;

//设置多久开启一次(小时:为单位)
var starttime = 8;

function init() {
	scheduleNew();
}

function scheduleNew() {
	em.setProperty("open", "false");
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时 24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * 60 * starttime; //设置多久开启
	}
	setupTask = em.scheduleAtTimestamp("startEvent", nextTime);
}

function startEvent() {
	em.setProperty("open", "true");
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时  24小时制
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	cal.set(java.util.Calendar.HOUR, 0); //设定的小时 12小时制
	cal.set(java.util.Calendar.MINUTE, startminute); //设定的分钟
	cal.set(java.util.Calendar.SECOND, 0); //设定的秒钟
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 *  60 * overtime; //设置多久结束
	}

	setupTask = em.scheduleAtTimestamp("finishEvent", nextTime);
	em.broadcastServerMsg(5121050, "敲打箱子活动已经开始啦，请通过万能NPCPPMS专属副本进入副本！", true);
	em.broadcastServerMsg("[敲打箱子]  活动已经开启。请玩家们通过万能NPCPPMS专属副本进入！" + overtime + "分钟后结束");
}

function finishEvent() {
	em.broadcastServerMsg("[敲打箱子] 本次活动已经圆满结束!!!砍箱子大门关闭 " + starttime + "个小时后会再次启动");
	scheduleNew();
}

function cancelSchedule() {
	if (setupTask != null) {
		setupTask.cancel(true);
	}
}
